package com.haruhinav.config;

import com.haruhinav.interecptors.AdminInterecptor;
import com.haruhinav.interecptors.JWTInterecptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class InterecptorConfig implements WebMvcConfigurer {

    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //获取文件的真实路径
        String path = System.getProperty("user.dir")+"\\src\\main\\resources\\static\\upload\\";
        //  String path1 = System.getProperty("user.dir")+"\\src\\main\\resources\\static\\static\\";
        //
        registry.addResourceHandler("/upload/**").addResourceLocations("file:"+path);
        // registry.addResourceHandler("/static/**").addResourceLocations("file:"+path1);
        //registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");

    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //InterceptorRegistration registration =

        registry.addInterceptor(new JWTInterecptor())
                .addPathPatterns("/**/a/**")
                .excludePathPatterns("/**/e/**");

        registry.addInterceptor(new AdminInterecptor())
                .addPathPatterns("/**/y/**")//拦截
                .excludePathPatterns("/**/x/**");//放行



//                .addPathPatterns("/api.haruhi/**")
//                .excludePathPatterns("/x/**");
    }

}
